package cn.scut.srp.service.impl;

import cn.scut.srp.mapper.TeacherMapper;
import cn.scut.srp.model.BaseResponse;
import cn.scut.srp.model.ResponseCode;
import cn.scut.srp.model.vo.CourseInfoVo;
import cn.scut.srp.model.vo.MessageVo;
import cn.scut.srp.service.TeacherService;
import cn.scut.srp.utils.JWTUtils;
import cn.scut.srp.utils.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;
    @Autowired
    JWTUtils jwtUtils;
    @Override
    public BaseResponse<ResponseCode> insertMeaasge(String teacherAccount, String messageContent) {
        teacherMapper.insertMeaasge(teacherAccount, messageContent);
        return ResponseUtil.OK("留言成功");
    }
    @Override
    public BaseResponse<ResponseCode> addCourse(String token,CourseInfoVo courseInfoVo) {
        Long teacherId = getTeacherIdByToken(token);
        teacherMapper.insertCourse(teacherId,courseInfoVo);
        return ResponseUtil.OK("课程添加成功");
    }

    @Override
    public Long getTeacherIdByToken(String token) {
        return teacherMapper.getTeacherByAccount((String) jwtUtils.analyzeToken(token).get("studentAccount")).getId();
    }
}